﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Domain.Shared;

namespace BonsaiScrum.Core.Domain
{
    /// <summary>
    /// This is a development project. In Command Query Separation, we are only using this object
    /// to contain business rules. That is why there are not public properties. If you want to get
    /// an object to show business data, use an object from the Query namespace.
    /// </summary>
    public class Sprint : BaseEntity<Sprint>
    {
        private string _description;
        private DateTime _start;
        private DateTime _end;
        private int _projectid;
        private IList<Story> _stories;
        private Manager _manager;

        protected Sprint()
        {
            _stories = new List<Story>();
        }

        public Sprint(DateTime start, DateTime end, string description, int project, Manager m)
            : this()
        {
            if (string.IsNullOrEmpty(description))
                throw new ArgumentNullException("description");

            CheckThatTheStartDateIsAfterTheEndDate(start, end);

            _description = description;
            _start = start;
            _end = end;
            _projectid = project;
            _manager = m;
        }

        public Sprint(DateTime start, DateTime end, string description)
            : this()
        {
            if (string.IsNullOrEmpty(description))
                throw new ArgumentNullException("description");

            CheckThatTheStartDateIsAfterTheEndDate(start, end);

            _description = description;
            _start = start;
            _end = end;
        }

        private void CheckThatTheStartDateIsAfterTheEndDate(DateTime start, DateTime end)
        {
            if (start.CompareTo(end) > 0)
                throw new ArgumentException("End date should be after the start date.");
        }

        public virtual void AddStory(Story storyToAdd)
        {
            if (storyToAdd == null)
                throw new ArgumentNullException("storyToAdd");

            _stories.Add(storyToAdd);
        }
    }
}
